#ifndef STATIONMODEL_H
#define STATIONMODEL_H

#include <QObject>
#include <QVariant>
#include <QString>
#include <QDateTime>
#include <QDebug>

namespace Moolink {


class StationModel : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString text READ text WRITE setText NOTIFY statusChanged)
    Q_PROPERTY(QString MN READ getMN WRITE setMN NOTIFY statusChanged)
    Q_PROPERTY(QString PW READ getPW WRITE setPW NOTIFY statusChanged)
    Q_PROPERTY(QString OverTime READ getOverTime WRITE setOverTime NOTIFY statusChanged)
    Q_PROPERTY(QString ReCount READ getReCount WRITE setReCount NOTIFY statusChanged)
    Q_PROPERTY(QString SystemTime READ getSystemTime WRITE setSystemTime NOTIFY statusChanged)
    Q_PROPERTY(QString RtdInterval READ getRtdInterval WRITE setRtdInterval NOTIFY statusChanged)
    Q_PROPERTY(QString MinInterval READ getMinInterval WRITE setMinInterval NOTIFY statusChanged)
    Q_PROPERTY(bool RealtimeReport READ getRealtimeReport WRITE setRealtimeReport NOTIFY statusChanged)
    Q_PROPERTY(bool DeviceStateView READ getDeviceStateView WRITE setDeviceStateView NOTIFY statusChanged)
    Q_PROPERTY(QString RestartTime READ getRestartTime WRITE setRestartTime NOTIFY statusChanged)
    Q_PROPERTY(QString SoftCurrVer READ getSoftCurrVer WRITE setSoftCurrVer NOTIFY statusChanged)
    Q_PROPERTY(QString SoftOnlineVer READ getSoftOnlineVer WRITE setSoftOnlineVer NOTIFY statusChanged)
    Q_PROPERTY(bool NeedUpdate READ getNeedUpdate WRITE setNeedUpdate NOTIFY statusChanged)
    Q_PROPERTY(QString SoftBuildOnTime READ getSoftBuildOnTime WRITE setSoftBuildOnTime NOTIFY statusChanged)

public:
    explicit StationModel(QObject *parent = nullptr) : QObject(parent) {

        data["MN"]="000000000000000000001111";
        data["PW"]="000000";
        data["RestartTime"]="20190101000000";
        data["SystemTime"]="20190101000000";
        data["OverTime"]="0";
        data["ReCount"]="0";
        data["RtdInterval"]="30";
        data["MinInterval"]="15";
        data["RealtimeReport"]=true;
        data["DeviceStateView"]=false;

    }
    QString text() { return m_text; }

    void setText(QString text) {
        m_text = text;
        emit statusChanged();
    }

    QString getMN() { return data["MN"].toString(); }
    void setMN(QString text) {data["MN"] = text; emit statusChanged();}

    QString getPW() { return data["PW"].toString(); }
    void setPW(QString text) {data["PW"] = text; emit statusChanged();}



    QString getOverTime() { return data["OverTime"].toString(); }
    void setOverTime(QString text) { data["OverTime"] = text; emit statusChanged();}

    QString getReCount() { return data["ReCount"].toString(); }
    void setReCount(QString text) { data["ReCount"] = text; emit statusChanged();}

    QString getSystemTime() { return data["SystemTime"].toString(); }
    void setSystemTime(QString text="yyyyMMddhhmmss") {/* data["SystemTime"] = text; */}
    void refreshSystemTime(){data["SystemTime"] = QDateTime::currentDateTime().toString("yyyyMMddhhmmss"); emit statusChanged();}



    QString getRtdInterval() { return data["RtdInterval"].toString(); }
    int getRtdIntervalInt() { return data["RtdInterval"].toInt(); }
    void setRtdInterval(QString text) { data["RtdInterval"] = text; emit statusChanged();}

    QString getMinInterval() { return data["MinInterval"].toString(); }
    int getMinIntervalInt() { return data["MinInterval"].toInt(); }
    void setMinInterval(QString text) { data["MinInterval"] = text; emit statusChanged();}

    bool getRealtimeReport() { return data["RealtimeReport"].toBool(); }
    void setRealtimeReport(bool text) { data["RealtimeReport"] = text; emit statusChanged();}

    bool getDeviceStateView() { return data["DeviceStateView"].toBool();; }
    void setDeviceStateView(bool text) { data["DeviceStateView"] = text; emit statusChanged();}

    QString getRestartTime() { return data["RestartTime"].toString(); }
    void setRestartTime(QString text="yyyyMMddhhmmss") { data["RestartTime"] = QDateTime::currentDateTime().toString(text); emit statusChanged();}

    QString getSoftCurrVer() { return _SoftCurrVer; }
    void setSoftCurrVer(QString text) {_SoftCurrVer = text; emit statusChanged();}

    QString getSoftOnlineVer() { return _SoftOnlineVer; }
    void setSoftOnlineVer(QString text) {_SoftOnlineVer = text; emit statusChanged();}

    QString getSoftBuildOnTime() { return _SoftBuildOnTime; }
    void setSoftBuildOnTime(QString text) {_SoftBuildOnTime = text; emit statusChanged();}


    bool getNeedUpdate() { return _NeedUpdate; }
    void setNeedUpdate(bool text) {_NeedUpdate = text; emit statusChanged();}

    void UpDateStationInfo(QVariantMap newdata)
    {
        data["MN"]=newdata["MN"].toString();
        data["PW"]=newdata["PW"].toString();
        data["OverTime"]=newdata["OverTime"].toString();
        data["ReCount"]=newdata["ReCount"].toString();
        data["MinInterval"]=newdata["MinInterval"].toString();
        data["OverTime"]=newdata["OverTime"].toString();
        data["RealtimeReport"]=newdata["RealtimeReport"].toBool();
        data["DeviceStateView"]=newdata["DeviceStateView"].toBool();
    }



    QVariantMap data;

    QVariantMap codeData05;
    QVariantMap codeData17;

    //QMap<QString, QVariant> stationdata;


    qint64 currTimeSec=0;
    qint64 startupTimeSec=0;
    qint64 rtdTimeSec=0;
    qint64 minTimeSec=0;
    qint64 hourTimeSec=0;
    qint64 dayTimeSec=0;

    qint64 reSendTimeSec=0;

    qint64 rtdRemainSec=0;
    qint64 minRemainSec=0;

signals:
    void statusChanged();
    //void sysTimeChanged();
public slots:
    void SoftUpdateDo(const QString &s){
        setSoftOnlineVer(s);
        setNeedUpdate(true);
        qDebug()<<"SoftUpdateDo:"<<s;
    }
private:
    QString m_text="txtTest";
//    QString _MN="000000000000000000001111";
//    QString _PW="000000";
//    QString _RestartTime="20190101000000";
//    QString _SystemTime="20190101000000";
//    QString _OverTime="0";
//    QString _ReCount="0";
//    QString _RtdInterval="60";
//    QString _MinInterval="10";
//    QString _RealtimeReport="否";
//    QString _DeviceStateView="否";


    QString _SoftCurrVer="";
    QString _SoftOnlineVer="";
    QString _SoftBuildOnTime="";
    bool _NeedUpdate=false;


};

}

#endif // STATIONMODEL_H
